package dnspod_cmd

import (
	"context"
	"fmt"
	"time"

	my_common "atomgit.com/openlinksaas-org/tencloud/common"
	"github.com/spf13/cobra"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
	dnspod_client "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod/v20210323"
)

var _listDomainCmd = &cobra.Command{
	Use: "listDomain",
	Run: func(cmd *cobra.Command, args []string) {
		client, err := dnspod_client.NewClient(common.NewCredential(my_common.CmdSecretId, my_common.CmdSecretKey), my_common.CmdRegion, profile.NewClientProfile())
		if err != nil {
			my_common.OutputError(err)
		}
		ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
		defer cancel()
		req := dnspod_client.NewDescribeDomainListRequest()
		res, err := client.DescribeDomainListWithContext(ctx, req)
		if err != nil {
			my_common.OutputError(err)
		}
		fmt.Println(res.ToJsonString())
	},
}
